package net.stogi.unicore.beyond.back.dao.impl;

import java.util.List;

import net.stogi.common.dao.impl.GenericHibernateDaoImpl;
import net.stogi.unicore.beyond.api.model.OutputType;
import net.stogi.unicore.beyond.back.dao.OutputTypeDao;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository("UnicoreBeyondBack.Repository.OutputTypeDao")
@Transactional
public class OutputTypeHibernateDaoImpl extends GenericHibernateDaoImpl<OutputType, Long> implements OutputTypeDao {

	@Autowired
	public OutputTypeHibernateDaoImpl(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	@Override
	@SuppressWarnings("unchecked")
	public OutputType loadByName(String name) {
		DetachedCriteria criteria = DetachedCriteria.forClass(OutputType.class);
		criteria.add(Restrictions.eq("name", name));

		List<OutputType> result = getHibernateTemplate().findByCriteria(criteria);
		if (result.size() > 0) {
			return result.get(0);
		}
		return null;
	}
}
